<?php
namespace Home\Controller;

/**
 * FeedbackController
 * 投票结果管理
 */
class FeedbackController extends CommonController {
    /**
     * 投票结果列表
     * @return
     */
    public function index() {
        $result = $this->getPagination('Feedback',$where,null,'id desc');
        
        $feedbacks = $result['data'];
        foreach ($feedbacks as $k => $v) {
            $where['id'] = array(in, $feedbacks[$k]['result']);
            $result = M('Vote')->where($where)->getField('name', true);
            $feedbacks[$k]['resultStr'] = implode(",", $result);
        }

        $this->assign('feedbacks', $feedbacks);
        $this->assign('rows_count', $result['total_rows']);
        $this->assign('page', $result['show']);
        $this->display();
    }
    
    /**
     *删除投票结果
     *@return
     */
    public function delete() {
        if (!isset($_GET['id'])) {
            $this->errorReturn('你需要删除的投票结果数据不存在！');
        }

        $feedback = M('Feedback')->getById($_GET['id']);
        if (empty($feedback)) {
            $this->errorReturn('你需要删除的投票结果数据不存在！');
        }

        $result = D('Feedback', 'Service')->delete($feedback['id']);
        if (false === $result['status']) {
            return $this->errorReturn('系统出错了！');
        }

        $this->successReturn("删除投票结果成功！");
    }
}
